version: '3.8'

services:
  users-service:
    labels:
      top.boticord.is-boticord: 'yes'
    depends_on:
      - postgres
    env_file:
      - .env
    image: 127.0.0.1:5000/users-service

  resources-service:
    labels:
      top.boticord.is-boticord: 'yes'
    depends_on:
      - postgres
    env_file:
      - .env
    image: 127.0.0.1:5000/resources-service

  search-service:
    labels:
      top.boticord.is-boticord: 'yes'
    depends_on:
      - postgres
    env_file:
      - .env
    image: 127.0.0.1:5000/search-service

  bot-service:
    labels:
      top.boticord.is-boticord: 'yes'
    depends_on:
      - postgres
    env_file:
      - .env
    image: 127.0.0.1:5000/bot

  nginx:
    labels:
      top.boticord.is-boticord: 'yes'
    image: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/templates/nginx.conf.template
    deploy:
      placement:
        constraints:
          - node.role == manager
    ports:
      - '127.0.0.1:80:80'
    environment:
      NGINX_ENVSUBST_OUTPUT_DIR: /etc/nginx
    env_file:
      - ./.env

  nats:
    labels:
      top.boticord.is-boticord: 'yes'
    image: nats

  meili:
    labels:
      top.boticord.is-boticord: 'yes'
    image: 'getmeili/meilisearch:v0.27.2'
    volumes:
      - meili:/meili_data
    env_file:
      - ./.env
    deploy:
      placement:
        constraints:
          - node.labels.top.boticord.type == storage-node

  adminer:
    labels:
      top.boticord.is-boticord: 'yes'
    image: adminer
      
  redis:
    labels:
      top.boticord.is-boticord: 'yes'
    image: redis
    command: --save 60 10
    volumes:
      - redis:/data

  postgres:
    labels:
      top.boticord.is-boticord: 'yes'
    image: postgres
    env_file:
      - ./.env
    volumes:
      - postgres:/var/lib/postgresql/data
    deploy:
      placement:
        constraints:
          - node.labels.top.boticord.type == storage-node

  system-prune:
    image: alpinelinux/docker-cli
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    command: docker container prune --force --filter="label=top.boticord.is-boticord" && docker image prune --force
    deploy:
      mode: global
      restart_policy:
        delay: 24h

volumes:
  postgres:
  redis:
  meili:
